#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <iostream>
#include "Piece.h"
#include "PlateauGL.h"
#include "PieceGL.h"
#include "loadppm.h"

//! [0]
class GLWidget : public QGLWidget
{
    Q_OBJECT

public:
    GLWidget(QWidget *parent = 0);
    ~GLWidget();

    QSize minimumSizeHint() const;
    QSize sizeHint() const;
	void setListPiece (std::list<Piece*>) ;
	std::list<Piece*> getListPiece () const ;

	static GLuint tex [4];
	
//! [0]


public slots:
	void pieceSelectionOn (bool player) ;
	void pieceSelectionOff () ;
	void positionSelectionOn (const std::list<Position> & positions) ;
	void positionSelectionOff () ;
	
	void setPieces (std::list<Piece*> pieces) ;
	void rotateScene () ;
	void toggleScene () ;

signals:
    void pieceSelected(PieceGL * pieceGl);
	void positionSelected(Position * position);

//! [2]
protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);
    void mousePressEvent(QMouseEvent *event);
//! [2]

//! [3]
private:
    GLuint makeObject();

	inline void setProjection() ;
	
	PieceGL * pickPiece(int x, int y, bool) ;
	Position * pickPosition(int x, int y, std::list<Position>&) ;
	
	double rapportAffichage ;
	PlateauGL monPlateau ;
	//PieceGL maPiece;
	std::list<Piece*> listPieces;
	QTimer * timer ; 
	
	double pasRotation ;
	double angleRotation ;
	double dangleRotation;
	double xrotation ;
	double dx ;
	bool sensRotation ;
	
	bool modeSelectionPiece ;
	bool modeSelectionPosition ;
	bool modeRotation ;
	
	bool currentPlayer ;
	std::list<Position> currentPositions ;
	QPoint lastEvent ;
};
//! [3]

#endif
